﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.ClientDW.Entities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.GCCS.Tests
{
    [TestClass]
    public class GCOverallCompanySummaryExtendedManagerTests
    {
        [TestMethod]
        public void GetCount_OverallAssessmentNull_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedCountGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessment = (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment) =>
                    {
                        return 123;
                    }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            int count = manager.GetCount(null, expectedUniverseIds, null);

            Assert.IsTrue(count == 123, "Returned value is incorrect.");
        }

        [TestMethod]
        public void GetCount_OverallAssessmentCompliant_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedCountGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessment = (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment) =>
                {
                    return 123;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            int count = manager.GetCount(null, expectedUniverseIds, GCAssessment.Compliant);

            Assert.IsTrue(count == 123, "Returned value is incorrect.");
        }

        [TestMethod]
        public void GetCount_OverallAssessmentNonCompliant_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedCountGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessment = (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment) =>
                {
                    return 123;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            int count = manager.GetCount(null, expectedUniverseIds, GCAssessment.NonCompliant);

            Assert.IsTrue(count == 123, "Returned value is incorrect.");
        }

        [TestMethod]
        public void GetCount_OverallAssessmentWatchList_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedCountGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessment = (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment) =>
                {
                    return 123;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            int count = manager.GetCount(null, expectedUniverseIds, GCAssessment.Watchlist);

            Assert.IsTrue(count == 123, "Returned value is incorrect.");
        }

        [TestMethod]
        public void GetList_AllNull_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            List<GCOverallCompanySummaryExtended> expectedValue = new List<GCOverallCompanySummaryExtended>
            {
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() }
            };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedListGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessmentNullableOfInt32NullableOfInt32StringArrayBoolean = 
                (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy, bool orderByAsc) =>
                    {
                        return expectedValue;
                    }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            var lst = manager.GetList(null, expectedUniverseIds, null, null, null, null);

            Assert.IsTrue(lst.Select(el => el.Id).SequenceEqual(expectedValue.Select(el => el.Id)), "Returned values are different than the expected values.");
        }

        [TestMethod]
        public void GetList_OverallAssessmentCompliant_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            List<GCOverallCompanySummaryExtended> expectedValue = new List<GCOverallCompanySummaryExtended>
            {
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() }
            };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedListGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessmentNullableOfInt32NullableOfInt32StringArrayBoolean =
                (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy, bool orderByAsc) =>
                {
                    return expectedValue;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            var lst = manager.GetList(null, expectedUniverseIds, GCAssessment.Compliant, null, null, null);

            Assert.IsTrue(lst.Select(el => el.Id).SequenceEqual(expectedValue.Select(el => el.Id)), "Returned values are different than the expected values.");
        }

        [TestMethod]
        public void GetList_OverallAssessmentNonCompliant_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            List<GCOverallCompanySummaryExtended> expectedValue = new List<GCOverallCompanySummaryExtended>
            {
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() }
            };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedListGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessmentNullableOfInt32NullableOfInt32StringArrayBoolean =
                (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy, bool orderByAsc) =>
                {
                    return expectedValue;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            var lst = manager.GetList(null, expectedUniverseIds, GCAssessment.NonCompliant, null, null, null);

            Assert.IsTrue(lst.Select(el => el.Id).SequenceEqual(expectedValue.Select(el => el.Id)), "Returned values are different than the expected values.");
        }

        [TestMethod]
        public void GetList_OverallAssessmentWatchList_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            List<GCOverallCompanySummaryExtended> expectedValue = new List<GCOverallCompanySummaryExtended>
            {
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() }
            };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedListGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessmentNullableOfInt32NullableOfInt32StringArrayBoolean =
                (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy, bool orderByAsc) =>
                {
                    return expectedValue;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            var lst = manager.GetList(null, expectedUniverseIds, GCAssessment.Watchlist, null, null);

            Assert.IsTrue(lst.Select(el => el.Id).SequenceEqual(expectedValue.Select(el => el.Id)), "Returned values are different than the expected values.");
        }

        [TestMethod]
        public void GetList_Success()
        {
            List<int> expectedUniverseIds = new List<int> { 1, 3, 5 };

            List<GCOverallCompanySummaryExtended> expectedValue = new List<GCOverallCompanySummaryExtended>
            {
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() },
                new GCOverallCompanySummaryExtended { Id = Guid.NewGuid() }
            };

            Sustainalytics.ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository repo = new ClientDW.DataAccessLayer.Fakes.StubIClientDWGlobalCompactRepository
            {
                GetGCOverallCompanySummaryExtendedListGCOverallCompanySummaryExtendedFiltersListOfInt32NullableOfGCAssessmentNullableOfInt32NullableOfInt32StringArrayBoolean =
                (GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy, bool orderByAsc) =>
                {
                    return expectedValue;
                }
            };

            var manager = new GCOverallCompanySummaryExtendedManager(repo);

            var lst = manager.GetList(null, expectedUniverseIds, GCAssessment.NonCompliant, 0, 123, null, true);

            Assert.IsTrue(lst.Select(el => el.Id).SequenceEqual(expectedValue.Select(el => el.Id)), "Returned values are different than the expected values.");
        }
    }
}
